package com.cs.manaer.controller;

import com.cs.manaer.controller.req.AppReleaseReqMsg;
import com.cs.manaer.controller.req.ListMenuReqMsg;
import com.cs.manaer.controller.res.ListAppReleaseResMsg;
import com.cs.manaer.po.AppRelease;
import com.cs.manaer.service.AppReleaseService;
import com.lin.common.rest.ResMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/web")
public class AppReleaseController {
    @Autowired
    private AppReleaseService appReleaseService;

    @PostMapping("/release/{id}/{optFlag}")
    public ResMsg<Integer> release(@PathVariable Long id, @PathVariable String optFlag) throws Exception {
        ResMsg<Integer> rm = new ResMsg<>();
        return rm.withData(appReleaseService.release(id, optFlag));
    }

    @PostMapping("/listrelease")
    public ResMsg<ListAppReleaseResMsg> listrelease(@Valid @RequestBody ListMenuReqMsg reqMsg) {
        ResMsg<ListAppReleaseResMsg> urs = new ResMsg<>();
        return urs.withData(appReleaseService.listAppRelease(reqMsg.getPageSize(), reqMsg.getPageNo()));
    }

    @PostMapping("/saverelease")
    public ResMsg<Integer> saverelease(@Valid @RequestBody AppReleaseReqMsg reqMsg) throws Exception {
        ResMsg<Integer> rm = new ResMsg<>();
        return rm.withData(appReleaseService.saveAppRelease(reqMsg));
    }

    @PostMapping("/release/{id}")
    public ResMsg<AppRelease> detail(@PathVariable Long id) {
        ResMsg<AppRelease> rm = new ResMsg<>();
        return rm.withData(appReleaseService.detail(id));
    }
}
